package net.tooeye.easymes.activities;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import net.tooeye.easyplus.R;

public class MainActivity extends AppCompatActivity {


    private LinearLayout layoutInputSfcta,layoutPandian,layoutTransfer,layoutReceive,layoutOther;

    private ImageView imageViewUser;
    private  TextView textViewUser;
    LinearLayout layout_message;
    LinearLayout layout_mocta;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ActionBar bar = getSupportActionBar();
        if (bar != null){
            bar.hide();
        }
        layoutInputSfcta = findViewById(R.id.inputSfcta);
        layoutPandian = findViewById(R.id.layoutPandian);
        layoutTransfer = findViewById(R.id.layoutTransfer);
        layoutReceive = findViewById(R.id.layoutReceive);
        textViewUser = findViewById(R.id.textViewUser);
        imageViewUser = findViewById(R.id.imageViewUser);
        layoutOther = findViewById(R.id.layout_other);
        layout_message = findViewById(R.id.layout_message);
        layout_mocta = findViewById(R.id.layout_mocta);
        layoutInputSfcta.setOnClickListener(new OpenSfctaListener());
        layoutPandian.setOnClickListener(new OpenPandianListener());
        layoutTransfer.setOnClickListener(new OpenTransferListener());
        layoutReceive.setOnClickListener(new OpenReceiveProductActivity());
        SharedPreferences sp = getSharedPreferences("easy_plus", Context.MODE_PRIVATE);
        textViewUser.setText(sp.getString("user",""));
        imageViewUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
                        .setTitle("确定要重新登录吗？")
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                            }
                        })
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent(MainActivity.this,LoginActivity.class);
                                intent.putExtra("auto",0);
                                startActivity(intent);
                                finish();
                            }
                        });
                AlertDialog ad = builder.create();
                ad.setCancelable(true);
                ad.show();
            }
        });
        layoutOther.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this,MoctaActivity.class));
            }
        });

        layout_message.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,WebAppActivity.class);
                intent.putExtra("url","/Appindex/Index/?client=android");
                startActivity(intent);
            }
        });
        layout_mocta.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,WebAppActivity.class);
                intent.putExtra("url","/Appindex/mocta?client=android");
                startActivity(intent);
            }
        });
    }

     /*
        打开报工输入窗体
      */
     class OpenSfctaListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            Intent intent  = new Intent(MainActivity
                    .this,SfctaActivity.class);
            startActivity(intent);
        }
    }
    //盘点
    class  OpenPandianListener implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            Intent  intent = new Intent(MainActivity
                    .this,PandianActivity.class);
            startActivity(intent);
        }
    }
    //转移
    class  OpenTransferListener implements  View.OnClickListener{
        @Override
        public void onClick(View v) {
            Intent  intent = new Intent(MainActivity
                    .this,TransferActivity.class);
            startActivity(intent);
        }
    }

    class  OpenReceiveProductActivity implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            Intent  intent = new Intent(MainActivity
                    .this,ReceiveProductActivity.class);
            startActivity(intent);
        }
    }

}
